#ifndef IDHELLOWORLDADAPTER_H
#define IDHELLOWORLDADAPTER_H

#include <QDBusAbstractAdaptor>
#include <QDBusConnection>
#include <QObject>
#include <functional>

class IDHelloWorldAdapter : public QObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "com.qt.examples.DHelloWorld")
public:
    explicit IDHelloWorldAdapter(std::function<void(QString msg)> func, QObject *parent = nullptr)
        : QObject{parent}
        , m_func(func)
    {
        QDBusConnection::sessionBus().connect(
            "com.qt.examples.DHelloWorld",  "/", "com.qt.examples.DHelloWorld",  "broadcastMessage",
            this, SLOT(slotBroadcastMessage(QString)));
    }

public slots:
    void slotBroadcastMessage(QString msg)
    {
        if (m_func)
        {
            m_func(msg);
        }
    }

private:
    std::function<void(QString msg)> m_func;
};

#endif // IDHELLOWORLDADAPTER_H
